import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:vape_xe/utils/utils.dart';
import 'package:vape_xe/values/values.dart';
import 'package:vape_xe/widgets/widgets.dart';

import 'logic.dart';

class WithdrawVerificationCodeView extends GetView<WithdrawVerificationCodeController> {
  const WithdrawVerificationCodeView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios_new_rounded),
          onPressed: () => {Navigator.of(context).pop('刷新')},
        ),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          30.hGap,
          Padding(
            padding: EdgeInsets.only(left: 32.w, right: 60.w),
            child: Text(
              'Please enter the verification code'.tr,
              style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.bold),
            ),
          ),
          12.hGap,
          Padding(
            padding: EdgeInsets.only(left: 32.w),
            child: Obx(
              () => Text(
                controller.arguments['type'] == 0
                    ? 'Verification code has been sent via SMS to +${controller.arguments['mobileType']} ${controller.arguments['mobile']}'
                    : 'Verification code has been sent to ${controller.arguments['email']}',
                style: TextStyle(fontSize: 12.sp, color: AppColors.thirdText),
              ),
            ),
          ),
          36.hGap,
          Center(
            child: VerificationCode(
              fullBorder: true,
              widthSize: 47.6.w,
              heightSize: 56.h,
              gapSize: 16.w,
              textStyle: TextStyle(fontSize: 20.sp, fontWeight: FontWeight.bold),
              keyboardType: TextInputType.number,
              underlineColor: Colors.white10,
              underlineUnfocusedColor: Colors.transparent,
              fillColor: Colors.white10,
              length: 6,
              onCompleted: (String value) {
                FocusScope.of(context).unfocus();
                controller.withdraw(value);
              },
              onEditing: (bool value) {},
            ),
          ),
          20.hGap,
          Center(
            child: GestureDetector(
              onTap: () => controller.sendVerificationCode(),
              child: Obx(
                () => Text(
                  controller.secondsRemaining == 0 ? 'Resend'.tr : 'Resend（${controller.secondsRemaining}s）',
                  style: TextStyle(
                    fontSize: 12.sp,
                    color: controller.secondsRemaining == 0 ? Colors.white : AppColors.thirdText,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
